package numbers;

import static org.junit.Assert.*;
import static numbers.CollectorUtil.*;

import numbers.FastGrowingNumberGenerator;
import numbers.INumberGenerator;
import numbers.NumberGenerator;
import numbers.SuperstitionRespectingNumberGenerator;

import org.junit.Test;

public class A1T02_NumberGeneratorTest {
	
	@Test
	public void generatingNumbersIsEasy() throws Exception {
		INumberGenerator generator = new NumberGenerator();
		assertEquals(0, generator.nextNumber());
		assertEquals(1, generator.nextNumber());
		assertEquals(2, generator.nextNumber());
		generator.setNextNumber(144);
		assertEquals(144, generator.nextNumber());
		assertEquals(145, generator.nextNumber());
		assertEquals(146, generator.nextNumber());
	}
	
	@Test
	public void youCanGetBigNumbers() throws Exception {
		INumberGenerator generator = new FastGrowingNumberGenerator(27068, 17);
		assertEquals(27068, generator.nextNumber());
		assertEquals(27068 + 1*17, generator.nextNumber());
		assertEquals(27068 + 2*17, generator.nextNumber());
		assertEquals(27068 + 3*17, generator.nextNumber());
	}

	@Test
	public void superstitionCanBeRespected() throws Exception {
		INumberGenerator generator = new SuperstitionRespectingNumberGenerator();
		generator.setNextNumber(11);
		assertEquals(11, generator.nextNumber());
		assertEquals(12, generator.nextNumber());
		// 13 is avoided
		assertEquals(14, generator.nextNumber());
		assertEquals(15, generator.nextNumber());
	}

	@Test
	public void nowItsEasyToCollectDifferentNumbers() throws Exception{
		int[] numbers;
		
		numbers = collectSomeNumbers(5, new NumberGenerator());
		assertArrayEquals(new int[] {0, 1, 2, 3, 4}, numbers);
		
		numbers = collectSomeNumbers(3, new FastGrowingNumberGenerator(55, 11));
		assertArrayEquals(new int[] {55, 66, 77}, numbers);
		
		numbers = collectSomeNumbers(20, new SuperstitionRespectingNumberGenerator());
		assertEquals(20, numbers.length);
		assertEquals(10, numbers[10]);
		assertEquals(20, numbers[19]);
	}

}
